﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Profile;
using System.Web.Security;
using Detai.Lib.Common;

namespace Detai.Web.Models
{
    public class UserProfile : ProfileBase
    {
        [SettingsAllowAnonymous(false)]
        public string FullName
        {
            get { return base["FullName"] as string; }
            set { base["FullName"] = value; }
        }

        [SettingsAllowAnonymous(false)]
        public string ProfessionID
        {
            get { return base["ProfessionID"] as string; }
            set { base["ProfessionID"] = value; }
        }
        [SettingsAllowAnonymous(false)]
        public string ProfessionName
        {
            get { return base["ProfessionName"] as string; }
            set { base["ProfessionName"] = value; }
        }
        [SettingsAllowAnonymous(false)]
        public string OrgnizationName
        {
            get { return base["OrgnizationName"] as string; }
            set { base["OrgnizationName"] = value; }
        }
        [SettingsAllowAnonymous(false)]
        public string OrgnizationID
        {
            get { return base["OrgnizationID"] as string; }
            set { base["OrgnizationID"] = value; }
        }
        [SettingsAllowAnonymous(false)]
        public string DepartmentID
        {
            get { return base["DepartmentID"] as string; }
            set { base["DepartmentID"] = value; }
        }
        [SettingsAllowAnonymous(false)]
        public string RecipientID
        {
            get { return base["RecipientID"] as string; }
            set { base["RecipientID"] = value; }
        }
        [SettingsAllowAnonymous(false)]
        public string ReplierID
        {
            get { return base["ReplierID"] as string; }
            set { base["ReplierID"] = value; }
        }
        [SettingsAllowAnonymous(false)]
        public string Description
        {
            get { return base["Description"] as string; }
            set { base["Description"] = value; }
        }

        public static UserProfile GetUserProfile(string username)
        {
            return Create(username) as UserProfile;
        }

        public static UserProfile GetUserProfile()
        {
            return Create(Membership.GetUser().UserName) as UserProfile;
        }
        // modified date 20/03/2011
        public static int GetOrganizationID() {
            var p = GetUserProfile();
            if (p != null)
            {
                if (p.OrgnizationID == null || p.OrgnizationID == string.Empty) return 0;
                else
                    return Utils.ParseInt(p.OrgnizationID);
            }
            else return 0;
        }
        public static int GetDepartmentID()
        {
            var p = GetUserProfile();
            if (p != null)
            {
                if (p.DepartmentID == null || p.DepartmentID == string.Empty) return 0;
                else
                    return Utils.ParseInt(p.DepartmentID);
            }
            else return 0;
        }
        public static int GetRecipientID()
        {
            var p = GetUserProfile();
            if (p != null)
            {
                if (p.RecipientID == null || p.RecipientID == string.Empty) return 0;
                else
                    return Utils.ParseInt(p.RecipientID);
            }
            else return 0;
        }
        public static int GetReplierID()
        {
            var p = GetUserProfile();
            if (p != null)
            {
                if (p.ReplierID == null || p.ReplierID == string.Empty) return 0;
                else
                    return Utils.ParseInt(p.ReplierID);
            }
            else return 0;
        }
    }
}
